<?php

/* @var $this yii\web\View */
/* @var $generator yii\gii\generators\crud\Generator */

/* @var $model \yii\db\ActiveRecord */
$model          = new $generator->modelClass();
$safeAttributes = $model->safeAttributes();
if (empty($safeAttributes)) {
	$safeAttributes = $model->attributes();
}

echo '<?php' . PHP_EOL;
?>

	$submit_url = '';
	$list_url   = \yii\helpers\Url::to(['index']);
	if ($action == 'create') {
	$submit_url = \yii\helpers\Url::to(['create']);
	} elseif ($action == 'save') {
	$submit_url = \yii\helpers\Url::to(['save']);
	}

<?= '?>' ?>

	<div class="easyui-panel" title="<?= '<?=$this->title;?>'; ?>" data-options="fit:true,border:false">
		<div class="easyui-panel" data-options="border:false">
			<form id="form" method="post">
				<input name="_csrf" type="hidden" id="_csrf" value="<?= '<?= \Yii::$app->request->csrfToken ?>' ?>">
				<input type="hidden" name="id" value="">
				<table class="form-table">
					<?php foreach ($generator->getColumnNames() as $attribute) {
						if (in_array($attribute, $safeAttributes)) {
							?>
							<tr>
								<td>
									<input name="<?= $attribute ?>" class="easyui-textbox" label="<?= $generator->getColumnLabel($attribute) ?>：" required="true">
								</td>
							</tr>
							<?php
						}
					} ?>
				</table>
			</form>
		</div>
		<div class="easyui-panel" data-options="height:'37px',border:true"
		     style="padding:5px 10px;border-left:none;border-right: none;border-bottom:none">
			<?= '<?php' ?>

			if ($action != 'view') {

			<?= '?>' ?>
			<a class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="$('#form').form('submit');">提交</a>
			<a class="easyui-linkbutton" data-options="iconCls:'icon-arrow_undo'" onclick="$('#form').form('reset');">重置</a>
			<?= '<?php' ?>
			}
			<?= '?>' ?>
			<a class="easyui-linkbutton" data-options="iconCls:'icon-back'" onclick="BX.goto('<?= '<?= $list_url ?>' ?>')">返回</a>
		</div>
	</div>
<?= '<?php \common\widgets\JsBlock::begin(); ?>' ?>
	<script type="application/javascript">
		var _form = $('#form');

		_form.form({
			success: function (data) {
				data = $.parseJSON(data);
				if (data.type == 'success') {
					$.messager.alert('提示', data.message, 'info', function () {
						// 跳转
						BX.goto('<?='<?=$list_url?>'?>');
					});
				} else {
					var errors = [];
					if (data.errors) {
						$.each(data.errors, function (k, v) {
							errors.push(v.join(''));
						});
					}
					$.messager.alert('提示', data.message + (errors ? ('<br>' + errors.join('<br>')) : ''), 'error');
				}
			}
		});

		<?='<?php'?>
		if ($action == 'save' || $action == 'view') {
			<?='?>'?>
			_form.form('load', <?='<?=json_encode(isset($data)?$data:[]);?>'?>);
			<?='<?php'?>
		}
		if ($action == 'view') {
			<?='?>'?>
			// 禁止表单
			$(function () {
				_form.form('disable');
			});
		<?='<?php }?>'?>
	</script>
<?= '<?php \common\widgets\JsBlock::end(); ?>' ?>